/*
 * PhoneDict: A J2ME Dict client
 * 
 * Copyright (C) 2006 Labeneator labeneator@gmail.org
 *
 * This file is a part of PhoneDict. PhoneDict is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the Free 
 * Software Foundation; either version 2 of the License, or (at your option) any later version.
 * Mobber is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * 
 */

package dict;

import java.io.*;

public class DictGet extends InputStreamReader {
	

	 public DictGet (InputStream in) throws IOException, UnsupportedEncodingException
     {
             super(in);
             getUAResponse();
     }
	public String getWelcome() throws IOException
	{
		System.out.println("In GetWelcome");
		StringBuffer response = new StringBuffer();
		int c = 0, p = 0;
        while (((c = read()) != -1)) {
        	if (p == '\r' && c == '\n')
        		break;
        	response.append((char) c);
        	p = c;
        }
        return response.toString();
	}

	
	public String getDefination() throws IOException
	{
		StringBuffer response = new StringBuffer();
		int c = 0, p = 0, p1=0, flagdot = 0, flagend = 0;
        while (((c = read()) != -1)) {
        	if (p == '\r' && c == '\n' && flagdot == 1)
        		flagend = 1;
        	else if (p1 == '\r' && p == '\n' && c == '.'){
        		flagdot = 1;
        		continue;
        	}
        	else if (p1 == '2' && p == '5' && c == '0' && flagend == 1)
        		break;
            response.append((char) c);
            p1 = p;
            p = c;
        }
        //Strip out the response terminators.
        response.delete(response.length()-7, response.length());
        return response.toString();
        
	}
	public String getMatch() throws IOException
	{
		StringBuffer response = new StringBuffer();
		int c = 0, p = 0, p1=0, flagdot = 0, flagend = 0;
        while (((c = read()) != -1)) {
        	if (p == '\r' && c == '\n' && flagdot == 1)
        		flagend = 1;
        	else if (p1 == '\r' && p == '\n' && c == '.'){
        		flagdot = 1;
        		continue;
        	}
        	else if (p1 == '2' && p == '5' && c == '0' && flagend == 1)
        		break;
            response.append((char) c);
            p1 = p;
            p = c;
        }
        //Strip out the response terminators.
        response.delete(response.length()-7, response.length());
        return response.toString();
        
	}
	public String getServerInfo() throws IOException
	{
		StringBuffer response = new StringBuffer();
		int c = 0, p = 0, p1=0;
        while (((c = read()) != -1)) {
        	if (p1 == '\r' && p == '\n' && c == '.' )
        		break;
            response.append((char) c);
            p1 = p;
            p = c;            
        }
        return response.toString();
        
	}
	public String getDatabases() throws IOException
	{
		StringBuffer response = new StringBuffer();
		int c = 0, p = 0, p1=0;
        while (((c = read()) != -1)) {
        	if (p1 == '\r' && p == '\n' && c == '.' )
        		break;
            response.append((char) c);
            p1 = p;
            p = c;            
        }
        return response.toString();
        
	}public String getStrategies() throws IOException
	{
		StringBuffer response = new StringBuffer();
		int c = 0, p = 0, p1=0;
        while (((c = read()) != -1)) {
        	if (p1 == '\r' && p == '\n' && c == '.' )
        		break;
            response.append((char) c);
            p1 = p;
            p = c;            
        }
        return response.toString();
        
	}
	public String getDatabaseInfo() throws IOException
	{
		StringBuffer response = new StringBuffer();
		int c = 0, p = 0, p1=0;
        while (((c = read()) != -1)) {
        	if (p1 == '\r' && p == '\n' && c == '.' )
        		break;
            response.append((char) c);
            p1 = p;
            p = c;            
        }
        return response.toString();        
	}
	public String getServerStatus() throws IOException
	{
		StringBuffer response = new StringBuffer();
		int c = 0, p = 0;
        while (((c = read()) != -1)) {
        	if (p == '\r' && c == '\n' )
        		break;
            response.append((char) c);
            p = c;            
        }
        return response.toString();        
	}
	public String getServerHelp() throws IOException
	{
		StringBuffer response = new StringBuffer();
		int c = 0, p = 0, p1=0;
        while (((c = read()) != -1)) {
        	if (p1 == '\r' && p == '\n' && c == '.' )
        		break;
            response.append((char) c);
            p1 = p;
            p = c;            
        }
        return response.toString();        
	}
	public void getUAResponse() throws IOException
	{
		StringBuffer response = new StringBuffer();
		int c = 0, p = 0;
        while (((c = read()) != -1)) {
        	if (p == '\r' && c == '\n')
        		break;
            response.append((char) c);
            p = c;            
        }
        System.out.println(response.toString());
        
	}
}
